import {observable, action} from "mobx";
import * as API from "../../api"

export default class StatisticsStore {
    @observable allDatas = {};

    @observable allnum;
    @observable doingnum;
    @observable landnum;
    @observable overnum;
    @observable prjinfos;
    @observable todonum;

    @observable seriesData = [];
    @observable legend = [];
    @observable option;
    @observable option2;
    @observable key = 0;
    echarts1;
    echarts2;

    @action
    init = () => {
        this.seriesData = [];
        this.getPrjCountChart();
    }
    @action
    clearAllOptions = () => {
        this.legend = [];
        this.prjinfos = [];
        this.seriesData = [];
    }
    @action
    getPrjCountChart = (params) => {
        API.getPrjCountChart(params).then(action(res => {
            this.allDatas = res;

            const {allnum, doingnum, landnum, mytasknum, overnum, todonum, prjinfos} = res;
            this.allnum = allnum;
            this.doingnum = doingnum;
            this.landnum = landnum;
            this.mytasknum = mytasknum;
            this.overnum = overnum;
            this.todonum = todonum;
            this.prjinfos = prjinfos;

            this.legend = prjinfos.map((data) => data.prjtypename);
            prjinfos.forEach((item) => {
                this.seriesData.push({
                    name: item.prjtypename,
                    value: item.num
                })
            });
            try {
                this.echarts1.clear();
                this.echarts1.paint();
                this.echarts2.clear();
                this.echarts2.paint();
            } catch (e) {

            }
        }))
    }
}
